package org.geektimes.configuration.microprofile.config;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @Author: menglinggang
 * @Date: 2021-03-15
 * @Time: 3:25 下午
 */
public class DefaultConfigSourceProvider implements ConfigSourceProvider {

    private List<ConfigSource> configSources = new LinkedList<>();

    public DefaultConfigSourceProvider(){
        ServiceLoader<ConfigSource> load = ServiceLoader.load(ConfigSource.class);
        load.forEach(configSources :: add);
    }
    @Override
    public Iterable<ConfigSource> getConfigSources(ClassLoader classLoader) {
        return Collections.unmodifiableList(configSources);
    }
}
